﻿/*
 * @file: BouquetBLL.cs
 * @in namespace: BLL
 */
using System;
using DAL;

/// <summary>
/// Summary description for BouquetBLL
/// </summary>
namespace BLL
{
    public class BouquetBLL
    {
        private BouquetBLL()
        {
            //
            // TODO: Add constructor logic here
            //
        }

        /// <summary>
        /// GetBouquets
        /// </summary>
        /// <param name="allowFilter">"true" enable ignore hidden records</param>
        /// <returns>Records corresponding</returns>
        public static Bouquet[] GetBouquets(bool allowFilter)
        {
            try
            {
                return DataAccessHelper.GetBouquetDA().GetBouquets(allowFilter);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        /// <summary>
        /// GetBouquetByOccasionID
        /// </summary>
        /// <param name="occasionID">Occasion ID</param>
        /// <param name="allowFilter">"true" enable ignore hidden records</param>
        /// <returns>Records corresponding</returns>
        public static Bouquet[] GetBouquetByOccasionID(int occasionID, bool allowFilter)
        {
            try
            {
                return DataAccessHelper.GetBouquetDA().GetBouquetByOccasionID(occasionID, allowFilter);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        /// <summary>
        /// GetBouquetByBouquetID
        /// </summary>
        /// <param name="bouquetID">Bouquet ID</param>
        /// <param name="allowFilter">"true" enable ignore hidden records</param>
        /// <returns>Record corresponding</returns>
        public static Bouquet GetBouquetByBouquetID(int bouquetID, bool allowFilter)
        {
            try
            {
                return DataAccessHelper.GetBouquetDA().GetBouquetByBouquetID(bouquetID, allowFilter);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        /// <summary>
        /// InsertBouquet
        /// </summary>
        /// <param name="_bouquet">Bouquet Entity</param>
        /// <param name="autoNumber">current Bouquet ID inserted</param>
        /// <returns>1 if successful, 0 if error occurred</returns>
        public static int InsertBouquet(Bouquet _bouquet, out int autoNumber)
        {
            try
            {
                if (_bouquet.OccasionID == 0)
                    throw new OnlineFloralDeliveryException(2, "OccasionID is not allow null or less than 0");
                else if (_bouquet.Name == null || _bouquet.Name.Length == 0)
                    throw new OnlineFloralDeliveryException(2, "Bouquet Name is not allow null or empty");
                else if (BouquetDA.BouquetNameExisted(_bouquet.Name) > 0)
                    throw new OnlineFloralDeliveryException(1, "Bouquet Name already exist");
                else if (_bouquet.Price == 0)
                    throw new OnlineFloralDeliveryException(2, "Price is not allow null or less than 0");
                else if (_bouquet.Quantity == 1)
                    throw new OnlineFloralDeliveryException(2, "Quantity is not allow null or less than 1");

                return DataAccessHelper.GetBouquetDA().InsertBouquet(_bouquet, out autoNumber);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        /// <summary>
        /// DisableBouquet
        /// </summary>
        /// <param name="bouquetID">Bouquet ID</param>
        /// <param name="isEnable">"true" if allow Bouquet enable, "false" if allow hidden Bouquet</param>
        /// <returns>1 if successful, 0 if error occurred</returns>
        public static int DisableBouquet(int bouquetID, bool isEnable)
        {
            try
            {
                return DataAccessHelper.GetBouquetDA().DisableBouquet(bouquetID, isEnable);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        /// <summary>
        /// UpdateBouquet
        /// </summary>
        /// <param name="_bouquet">Bouquet Entity</param>
        /// <returns>1 if successful, 0 if error occurred</returns>
        public static int UpdateBouquet(Bouquet _bouquet)
        {
            try
            {
                if (_bouquet.BouquetID == 0)
                    throw new OnlineFloralDeliveryException(2, "BouquetID is not allow null or less than 0");
                else if (_bouquet.OccasionID == 0)
                    throw new OnlineFloralDeliveryException(2, "OccasionID is not allow null or less than 0");
                else if (_bouquet.Name == null || _bouquet.Name.Length == 0)
                    throw new OnlineFloralDeliveryException(2, "Bouquet Name is not allow null");
                else if (BouquetDA.BouquetNameExisted(_bouquet.Name) > 0)
                    throw new OnlineFloralDeliveryException(1, "Bouquet Name already exist");
                else if (_bouquet.Price == 0)
                    throw new OnlineFloralDeliveryException(2, "Price is not allow null or less than 0");
                else if (_bouquet.Quantity == 0)
                    throw new OnlineFloralDeliveryException(2, "Quantity is not allow null or less than 0");

                return DataAccessHelper.GetBouquetDA().UpdateBouquet(_bouquet);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
    }
}